<template>
	<view>
		<u-navbar title-color="#717171" :background="{ backgroundColor: '#ffffff' }" :back-text-style="{color: '#fff'}" :title="$t('pressrelease.headlines')">
			<view class="navbar-right" slot="right">
				<view class="message-box right-item">
					<button @click="submit" style="background-color: #ed4141;color: #fff;margin-right: 20rpx;" size="mini">{{$t('pressrelease.release')}}</button>
				</view>
			</view> 
		</u-navbar>
		<view class="head_text">
			<textarea v-model="content" :placeholder="$t('pressrelease.content')"></textarea>
			<u-upload :max-size="5 * 1024 * 1024" max-count="9" :upload-text="$t('pressrelease.picture')" :auto-upload="false" @on-choose-complete="completedata"></u-upload>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				imgList: []
			};
		},
		methods: {
			//监听图片列表
			completedata(e) {
				var ss = {}
				const users = e.map(item => (ss.uri = item.url, ss.name = 'pics', ss));
				this.imgList = users
			},
			//发布
			async submit() {
				let data = {}
				data.content = this.content
				const res = await this.$myUploadFile({
					url: '/dmh/add-topline',
					header: {},
					formData: data,
					files: this.imgList
				})

				if (res.code == 200) {
					this.$refs.uToast.show({
						title: this.$i18n.messages[this.$i18n.locale].pressrelease.successfully,
						type: 'success'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						});
					}, 1000)

				} else {
					this.$refs.uToast.show({
						title: this.$i18n.messages[this.$i18n.locale].pressrelease.failed,
						type: 'error'
					})
				}
			},
		}
	}
</script>

<style lang="scss">
	.head_text {
		padding: 20rpx;
		width: 100%;

		textarea {
			width: 100%;
			border-radius: 3px;
			background-color: #eceff7;
		}
	}
</style>
